<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->decimal('order_total_price')->comment('订单总金额');
            $table->decimal('order_real_price')->comment('订单实际总金额');
            $table->decimal('goods_total_price')->comment('订单里面的商品总金额，不包含运费');
            $table->decimal('freight')->nullable()->comment('运费');
            $table->integer('order_score')->nullable()->comment('所得积分');
            $table->tinyInteger('is_invoice')->default(0)->comment('是否需要发票');
            $table->string('invoice_client')->nullable()->comment('发票抬头');
            $table->tinyInteger('is_refund')->default(1)->comment('是否可用退款');
            $table->datetime('paid_at')->nullable()->comment('付款时间');
            $table->tinyInteger('deliver_type')->nullable()->comment('提货方式 1：送货上门 2:自提');
            $table->string('order_number')->comment('订单编号');
            $table->string('address_info')->comment('冗余的收货地址,防止用户删除收货地址后造成的数据不一致');
            $table->integer('address_id')->comment('收货地址id');
            $table->string('remark')->nullable()->comment('用户附言');
            $table->string('payment_method')->nullable()->comment('支付方式');
            $table->datetime('arrive_time')->nullable()->comment('预计到货时间');
            $table->tinyInteger('status')->default(0)->comment('订单状态 0：未付款 1：未发货(已付款) 2：已发货 3：待评论 4：退货中 5:已完成 6:订单失效 7:订单关闭,8:退货完成');
            $table->integer('coupon_id')->nullable()->comment('优惠券id');
            $table->string('pay_number')->nullable()->comment('第三方支付流水号');
            $table->string('logistics_number')->nullable()->comment('快递单号');
            $table->integer('user_id')->comment('下单用户的用户id');
            $table->string('refund_reason')->nullable()->comment('退货原因');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
